package com.tongcao.cn.mapstruct.mapper;

import com.tongcao.cn.mapstruct.Person;
import com.tongcao.cn.mapstruct.PersonDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author:tongcao
 * @since:2019/6/26 14:17
 * Description:
 */
@Mapper
public interface PersonConverter {

    PersonConverter INSTANCE = Mappers.getMapper(PersonConverter.class);

    /**
     * 如果某个属性你不想映射，可以加个 ignore=true
     *
     * @param person
     * @return
     */
    @Mappings(value = {
            @Mapping(source = "birthday", target = "birth"),
            @Mapping(source = "birthday", target = "birthDateFormat", dateFormat = "yyyy-MM-dd HH:mm:ss"),
            @Mapping(target = "birthExpressionFormat", expression = "java(org.apache.commons.lang3.time.DateFormatUtils.format(person.getBirthday(),\"yyyy-MM-dd HH:mm:ss\"))"),
            @Mapping(source = "user.age", target = "age"),
            @Mapping(target = "email", ignore = false)
    })
    PersonDTO domain2dto(Person person);

    List<PersonDTO> listDomian2Dto(List<Person> people);
}